#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
using namespace std;

void calcParametricCoord(const double query[2], const double p1[2],
                         const double p2[2], const double p3[2],
                         const double p4[2], double parm_coord[2]) {
  double u{0.5}, v{0.5}, u1, v1, jacob[2][2], inv[2][2], f[2], du, dv;
  int iter;
  for (iter = 0; iter < 20; ++iter) {
    //   计算jacob
    for (int m = 0; m < 2; ++m) {
      jacob[m][0] =
          -p1[m] * (1.0 - v) + p2[m] * (1.0 - v) + p3[m] * v - p4[m] * v;
      jacob[m][1] =
          -p1[m] * (1.0 - u) - p2[m] * u + p3[m] * u + p4[m] * (1.0 - u);
    }
    double tmp = jacob[0][0] * jacob[1][1] - jacob[0][1] * jacob[1][0];
    inv[0][0] = jacob[1][1] / tmp;
    inv[0][1] = -jacob[0][1] / tmp;
    inv[1][0] = -jacob[1][0] / tmp;
    inv[1][1] = jacob[0][0] / tmp;
    for (int m = 0; m < 2; ++m)
      f[m] = p1[m] * (1.0 - u) * (1.0 - v) + p2[m] * u * (1.0 - v) +
             p3[m] * u * v + p4[m] * v * (1.0 - u) - query[m];
    u1 = u - (inv[0][0] * f[0] + inv[0][1] * f[1]);
    v1 = v - (inv[1][0] * f[0] + inv[1][1] * f[1]);
    u1 = fmin(1.0, fmax(0.0, u1));
    v1 = fmin(1.0, fmax(0.0, v1));
    du = u1 - u;
    dv = v1 - v;
    if (sqrt(du * du + dv * dv) <= 1.0e-12)
      break;
    u = u1;
    v = v1;
  }
  parm_coord[0] = u1;
  parm_coord[1] = v1;
  //   cout << "iter = " << iter << endl;
}

int main() {
  //   double fnode[4][2]{{0, 0}, {0, 2}, {1, 2}, {1, 0}};
  //   double query[2]{0.1, 0.6}, parm[2];
  double fnode[4][2]{{20.2009810796476, 2.6627179797917},
                     {20.2240815573729, 2.7},
                     {20.23714725, 2.7},
                     {20.2138417574864, 2.66270341563888}};
  double query[2]{2.021443227472858e+01, 2.663648440770904e+00}, parm[2];
  calcParametricCoord(query, fnode[0], fnode[1], fnode[2], fnode[3], parm);
  cout << setprecision(15) << scientific;
  cout << parm[0] << "  " << parm[1] << endl;
  return 0;
}